package com.wms.controller;

import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.entity.CategoryOrder;
import com.wms.service.CategoryOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "skh-类别顺序")
public class CategoryOrderController {
    @Autowired
    CategoryOrderService categoryOrderService;

    /**
     * 类别顺序列表
     * @return
     */
    @GetMapping("/category/")
    @ApiOperation("类别顺序")
    public ResultBean<List<CategoryOrder>> queryTree(){
        List<CategoryOrder> categoryList = categoryOrderService.queryTree();
        if (categoryList.isEmpty()){
            return R.fail("暂无分类数据");
        }
        return R.success("查询成功",categoryList);
    }

    @PutMapping("/category/order")
    @ApiOperation("修改类别顺序")
    public ResultBean updateCategoryOrder(@RequestParam int id, @RequestParam int orderNum){
        int rs = categoryOrderService.updateCategoryOrder(id,orderNum);
        return rs==1? R.success("修改成功"):R.fail("修改失败");
    }
}
